<?php  // $Id: systemconfig.php,v 1.7.8.1 2007/01/31 09:36:52 ajdonnison Exp $

if (!defined('DP_BASE_DIR')) {
	die('You should not access this file directly');
}

// check permissions
if (!$canEdit) {
	$AppUI->setMsg('Access denied', UI_MSG_ERROR);
	$AppUI->redirect();
}

$dPcfg = new CConfig();

// retrieve the system configuration data
$rs = $dPcfg->loadAll('config_group');

// retrieve any state parameters
if (isset( $_GET['tab'] )) {
	$AppUI->setState( 'ConfigIdxTab', $_GET['tab'] );
}
$tab = $AppUI->getState( 'ConfigIdxTab' ) !== NULL ? $AppUI->getState( 'ConfigIdxTab' ) : 0;
$active = intval( !$AppUI->getState( 'ConfigIdxTab' ) );

$titleBlock = new CTitleBlock('System Configuration');
$titleBlock->addButton( 'Main page', '?m=system' );
$titleBlock->show();

if (is_dir(DP_BASE_DIR.'/install')) {
	$AppUI->setMsg('You have not removed your install directory, this is a major security risk!', UI_MSG_ALERT);
	$msgAutoHide = 'click';
}
?>
<script>
function showHelpContext(id) {
	var help = $(id).innerHTML;
	var handler = $('idSystemHelp');
	handler.innerHTML = '<b>'+help+'</b>';
	handler.style.width = (help.length > 150) ? '400px' : '250px';
	handler.onclick = function() { Dialog('idSystemHelp').hide(); }
	Dialog('idSystemHelp').show();
}
</script>
<div id="idSystemHelp" class="popup" autohide="click" style="visibility: hidden; padding: 8px"></div>
<form name="cfgFrm" action="index.php?m=system&a=systemconfig" method="post">
<input type="hidden" name="dosql" value="do_systemconfig_aed" />
<table cellspacing="0" cellpadding="3" border="0" class="infopanel" width="100%">
	<tr>
		<td>
			<input class="button" type="submit" name="do_save_cfg" value="<?=$AppUI->_('Save')?>"/>
		</td>
		<td align="right">
			<div onclick="showHelpContext('sys')" class="button" style="width: 64px" valign="middle"><img class="ico" src="images/help.gif"> Help </div>
			<span id="sys" style="display: none"><?=$AppUI->_('syscfg_intro')?></span>
		</td>
	</tr>
</table>
<?
// prepare the automated form fields based on db system configuration data
$output  = null;
$last_group = '';
foreach ($rs as $c) {
	$value = '';
	switch ($c['config_type']) {
		case 'select':
			// Build the select list.
			$entry = '<select class="text" name="dPcfg['.$c['config_name'].']" style="width: 205px">';
			// Find the detail relating to this entry.
			$children = $dPcfg->getChildren($c['config_id']);
			foreach ($children as $child) {
				$entry .= '<option value="'.$child['config_list_name'].'"';
				if ($child['config_list_name'] == $c['config_value'])
					$entry  .= ' selected="selected"';
				$entry .= '>' . $AppUI->_($child['config_list_name'] . '_item_title') . '</option>';
			}
			$entry .= '</select>';
			break;
		case 'checkbox':
			$extra = ($c['config_value'] == 'true') ? "checked='checked'" : '';
			$value = 'true';
			// allow to fallthrough
		default:
			if (! $value) $value = $c['config_value'];
			$class = $c['config_type'] != 'checkbox' ? 'text' : '';
			$size = $c['config_type'] != 'checkbox' ? ' style="width: 200px" ' : '';
			$entry = '<input class="'.$class.'" type="'.$c['config_type'].'" '.$size.
						'name="dPcfg['.$c['config_name'].']" value="'.$value.'" '.$extra.'/>';
			break;
	}

	if ($c['config_group'] != $last_group) {
		$output .= '<tr><th colspan="2"><b>' . $AppUI->_($c['config_group'] .'_group_title') . '</b></th></tr>';
		$last_group = $c['config_group'];
	}

	$context = 'idContext_'.$c['config_name'];
	$output .=
	   '<tr>'.
			'<td class="item" width="150px">'.$AppUI->_($c['config_name'].'_title').'</td>'.
			'<td align="left" valign="top">'.$entry.'&nbsp;'.
				'<img class="ico clickable" src="images/help.gif" onclick="showHelpContext(\''.$context.'\')"/>'.
				'<span id="'.$context.'" style="display: none">'.
					$AppUI->_($c['config_name'].'_tooltip').
				'</span>'.
				'<input type="hidden" name="dPcfgId['.$c['config_name'].']" value="'.$c['config_id'].'"/>'.
			'</td>'.
		'</tr>';
}
?>
<table cellspacing="0" cellpadding="5" border="0" class="subinfopanel" width="100%">
	<?=$output?>
</table>
</form>
